package arisufascion.com.adapter;

import java.util.List;


import android.content.Context;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;
import arisufascion.com.R;

public class BannerGalleryAdapter extends ArrayAdapter<Integer>{
	public static final int BANNER_WIDTH = 320;
	public static final int BANNER_HEIGHT = 150;
	/**
	 * LayoutInflater を保持します。
	 */
	private LayoutInflater inflater;
	/**
	 * context を保持します。
	 */
	private Context context;

	public BannerGalleryAdapter(Context context, List<Integer> items) {
		super(context, 0, items);
		this.context = context; 
		
		this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	@Override
	public View getView(int position, View view, ViewGroup parent) {
		Integer item = getItem(position);

		// ビューを生成します。
		//view = this.adapterViewInflater.inflateBannerItemView(view, item);
		if (null == view) {
			view = inflater.inflate(R.layout.list_item_banner, null);
		}

		ImageView bannerImage = (ImageView) view.findViewById(R.id.bannerImage);

		Display display = this.getWindowSize();
		int windowWidth = display.getWidth();
		int bannerImageWidth = windowWidth ;
		float scale = (float) bannerImageWidth / (float) BANNER_WIDTH;
		int bannerImageHeight = (int) (scale * BANNER_HEIGHT);
		bannerImage.setLayoutParams(new LayoutParams(bannerImageWidth, bannerImageHeight));

		bannerImage.setImageResource(item);
		
		return view;
	}

	private Display getWindowSize() {
		WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
		Display display = windowManager.getDefaultDisplay();

		return display;
	}

}
